package com.onlyMe.serialization
{
	import com.flesler.componentas.core.Destroyable;
	
	import flash.utils.ByteArray;
	
	// One time use
	public final class IsleSerializer implements Destroyable
	{
		private var stream:ByteArray; 
		
		public function IsleSerializer()
		{
			init();
		}
		
		private function init():void
		{
			stream = new ByteArray();
		}
		
		public function append(ba:ByteArray):void
		{
			var len:int = ba.length;
			ba.position = 0;
			stream.writeShort(len);
			stream.writeBytes(ba, 0, len);
		}
		
		public function flush():ByteArray
		{
			var s:ByteArray = stream;
			s.position = 0;
			init();
			return s;
		}
		
		public function destroy():void
		{
			stream = null;
		}

	}
}